package com.lhd.ivos.vehicle.controller;

import com.lhd.ivos.base.response.JsonResult;
import com.lhd.ivos.vehicle.pojo.dto.VehicleQuery;
import com.lhd.ivos.vehicle.pojo.dto.VehicleSaveParam;
import com.lhd.ivos.vehicle.pojo.vo.VehicleVO;
import com.lhd.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lhd
 * date 2024/5/22
 * @apiNote
 */
@Slf4j
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆信息 vehicleQuery:{}",vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult addVehicle(VehicleSaveParam vehicleSaveParam){
        log.info("添加车辆信息{}",vehicleSaveParam);
        vehicleService.save(vehicleSaveParam);
        return JsonResult.ok();
    }

    @DeleteMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.info("删除车辆信息 id:{}",id);
        vehicleService.delete(id);
        return JsonResult.ok();
    }

    @GetMapping("unbind/{vehicleId}")
    public JsonResult unbindGeofence(@PathVariable Long vehicleId){
        log.debug("解绑车辆和围栏关系 vehicleId = {}",vehicleId);
        vehicleService.unbindGeofence(vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geofenceId}/{vehicleId}")
    public JsonResult updateVehicle(@PathVariable Long geofenceId,@PathVariable Long vehicleId){
        log.debug("绑定车辆和围栏关系 geofenceId = {}, vehicleId = {}",geofenceId,vehicleId);
        vehicleService.bindGeofenceAndVehicle(geofenceId,vehicleId);
        return JsonResult.ok();
    }
}
